(:
  A procedure to select the contents of the textboard, regardless of it being tokentextboard or not.
:)
declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
<display>{
let $t := $arguments[1]
let $d := doc($t)/trace/event
for $e at $p in $d
where $e[textboard] or $e[tokentextboard/text]
return
  <item>{
    <info name="type">textboard</info> ,
    <info name="time">{ $e/time }</info>,
    <info name="src-anchor">{
      <anchor>{
        <doc>{ $t }</doc>,
        <path>{jj:build-Path($e)}</path>
      }</anchor>
    }</info>,
    <info name="user">{string($e/@user)}</info>,
    <info name="room">{string($e/@room)}</info>,
    <info name="context">{
    let $pos := xs:integer($e/(textboard|tokentextboard)/text/@caret) + 1
	let $contextsize := 3
	let $before := fn:substring($e/textboard/text,1,$pos)
	let $split := fn:tokenize($before,"\s")
	return fn:string-join($split[position() ge (last()-$contextsize)], " ")
    }</info>,
    <info name="currenttext">{$e/(textboard|tokentextboard)/text}</info>,
    <info name="cursorposition">{string($e/(textboard|tokentextboard)/text/@caret)}</info>
  }</item>
}</display>
